package com.ys.http.network;


import java.util.HashMap;
import java.util.Map;

public class Params {

    private final Map<String, String> mMaps;

    protected Params(Map<String, String> map) {
        mMaps = map;
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    protected Map<String, String> get() {
        return mMaps;
    }

    public static class Builder {
        private final Map<String, String> map;

        public Builder() {
            map = new HashMap<>();
        }

        public Builder add(String name, String value) {
            if (isValidate(name, value)) {
                map.put(name, value);
            }
            return this;
        }

        public Builder add(String name, Number value) {
            if (isValidate(name, value)) {
                map.put(name, value.toString());
            }
            return this;
        }

        public Builder add(String name, boolean value) {
            if (name != null) {
                map.put(name, String.valueOf(value));
            }
            return this;
        }

        private boolean isValidate(String name, Object value) {
            return name != null && value != null;
        }

        public Params build() {
            return new Params(map);
        }
    }
}
